package com.itheima.tliasmanagementspringboot.aspect;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 演示通知类型
 */
@Component
//@Aspect
@Slf4j
public class Aspect2 {
    //定义一个切入点表达式,抽取重复的表达式
    @Pointcut("execution(* com.itheima.tliasmanagementspringboot.service.*.*(..))")
    public void point(){}

    @Before("point()")
    public void before(){
        System.out.println("前置通知-Before");
    }
    @After("point()")
    public void after(){
        System.out.println("最终通知-After");
    }
    @AfterReturning("point()")
    public void afterReturning(){
        System.out.println("后置通知-AfterReturning");
    }
    @AfterThrowing("point()")
    public void afterThowing(){
        System.out.println("异常通知");
    }
    @SneakyThrows //lombok里面的
    @Around("point()")
    public Object around(ProceedingJoinPoint joinPoint){
        System.out.println("环绕通知Around-前");
        Object result = joinPoint.proceed();
        System.out.println("环绕通知Around-后");
        return result;
    }

}
